package com.hq.fxh.No1_Infromation.Infor.Activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.github.lzyzsd.jsbridge.BridgeHandler;
import com.github.lzyzsd.jsbridge.BridgeWebView;
import com.github.lzyzsd.jsbridge.CallBackFunction;
import com.hq.fxh.CustomerView.MyTextView;
import com.hq.fxh.CustomerView.PopupWindow.PopupForComment;
import com.hq.fxh.CustomerView.ShareDialogUtils;
import com.hq.fxh.HttpApi.ArticleServiceImpl;
import com.hq.fxh.HttpApi.UserServiceImpl;
import com.hq.fxh.Intefers.NetworkSubscriber;
import com.hq.fxh.Modle.AutoNewsModle;
import com.hq.fxh.Modle.FavotityListGetModle;
import com.hq.fxh.Modle.KanTieListModle;
import com.hq.fxh.Modle.MyResponseBody;
import com.hq.fxh.Modle.SelectByCategoryIdRes;
import com.hq.fxh.Modle.ShareArticleRes;
import com.hq.fxh.Modle.ShareArticlesRes;
import com.hq.fxh.No0_ChengQu.Activity.News_AddAD_DetailActivity;
import com.hq.fxh.No0_ChengQu.Activity.BaseActivity;
import com.hq.fxh.No0_ChengQu.Login.LoginActivity;
import com.hq.fxh.No1_Infromation.Video.Activity.VideoDetailsActivity;
import com.hq.fxh.No2_BBS.Activity.Plate_DetialActivity;
import com.hq.fxh.No3_TuiGuang.MyMoBan.Activity.item.ToastUtils;
import com.hq.fxh.No3_TuiGuang.MyMoBan.AdEditorActivity;
import com.hq.fxh.No3_TuiGuang.MyMoBan.Model.CommonRes;
import com.hq.fxh.No3_TuiGuang.MyMoBan.Model.GetAdvertByUidRes;
import com.hq.fxh.No3_TuiGuang.MyMoBan.Model.ShareInfo;
import com.hq.fxh.R;
import com.hq.fxh.Utils.AppConstant;
import com.hq.fxh.Utils.ShareUtils;
import com.hq.fxh.Utils.ClickUtils;
import com.hq.fxh.Utils.IntentUtils;
import com.hq.fxh.Utils.LogUtils;
import com.hq.fxh.Utils.SharedPreferenceUtils;
import com.hq.fxh.Utils.Tool;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.Serializable;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import rx.Subscriber;

import static android.R.attr.breadCrumbShortTitle;
import static android.R.attr.id;
import static cn.jiguang.analytics.android.d.b;
import static cn.jiguang.analytics.android.d.d;


public class News_DetailsActivity extends BaseActivity implements View.OnClickListener {

    private static PopupForComment customPopupForComment;
    protected LinearLayout detailBack;
    protected LinearLayout detailMore;
    protected ImageView imageShouChang;
    protected ImageView imageDetailsMore;
    private BridgeWebView newsDetails;
    protected TextView imageNewsDetailsWrite;
    protected LinearLayout imageNewsDetailsComment;
    protected LinearLayout imageNewsDetailsShouChang;
    protected LinearLayout imageNewsDetailsShare;
    protected MyTextView addAd;
    private String newUrl;


    private boolean idShouChang = true;
    private int uid = 0, newId = 0;
    private int articleId;
    AutoNewsModle newsDetailData;
    private ShareDialogUtils shareDialogUtils;
    ShareArticlesRes.DataBean tuiDetailData;
    KanTieListModle.DataBean plateDetailData;
    FavotityListGetModle.DataBean favoriteDetailData;
    int type;// 0 新闻  1 帖子  2 推广  3 收藏
    boolean isShouChang = true;
    private ShareInfo shareInfo;
    private int memberId;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_news_details;
    }

    @Override
    protected void initView() {
        memberId = SharedPreferenceUtils.getMemberId(this);
        shareInfo = new ShareInfo();
        detailBack = (LinearLayout) findViewById(R.id.detail_Back);
        detailBack.setOnClickListener(News_DetailsActivity.this);
        detailMore = (LinearLayout) findViewById(R.id.detail_More);
        detailMore.setOnClickListener(News_DetailsActivity.this);
        newsDetails = (BridgeWebView) findViewById(R.id.webView_NewsDetails);
        imageNewsDetailsWrite = (TextView) findViewById(R.id.image_NewsDetails_Write);
        imageNewsDetailsWrite.setOnClickListener(News_DetailsActivity.this);
        imageNewsDetailsComment = (LinearLayout) findViewById(R.id.image_NewsDetails_Comment);
        imageNewsDetailsComment.setOnClickListener(News_DetailsActivity.this);
        imageNewsDetailsShouChang = (LinearLayout) findViewById(R.id.image_NewsDetails_ShouChang);
        imageNewsDetailsShouChang.setOnClickListener(News_DetailsActivity.this);
        imageNewsDetailsShare = (LinearLayout) findViewById(R.id.image_NewsDetails_Share);
        imageNewsDetailsShare.setOnClickListener(News_DetailsActivity.this);
        addAd = (MyTextView) findViewById(R.id.addAd);
        addAd.setOnClickListener(News_DetailsActivity.this);
        imageShouChang = (ImageView) findViewById(R.id.image_ShouChang);
        imageDetailsMore = (ImageView) findViewById(R.id.image_Details_More);
    }


    @Override
    protected void initData() {
        shareDialogUtils = new ShareDialogUtils(News_DetailsActivity.this, imageNewsDetailsComment);

        uid = SharedPreferenceUtils.getMemberId(this);
        Intent intent = getIntent();
        newUrl = intent.getStringExtra("url");
        type = intent.getIntExtra("type", -1);
        switch (type) {
            case 0:
                try {
                    Serializable data = intent.getSerializableExtra("data");
                    newsDetailData = (AutoNewsModle) data;
                    newId = newsDetailData.getArticle_id();

                    LogUtils.e("加载分享数据");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case 1:
                try {

                    Serializable data = intent.getSerializableExtra("data");
                    plateDetailData = (KanTieListModle.DataBean) data;
                    newId = plateDetailData.getPost_id();
                    int is_favorite = plateDetailData.getIs_favorite();
                    if (is_favorite == 0) {
                        isShouChang = true;
                        ClickUtils.clickShouChang(News_DetailsActivity.this, imageShouChang, false);


                    } else {
                        isShouChang = false;
                        ClickUtils.clickShouChang(News_DetailsActivity.this, imageShouChang, true);


                    }
                    LogUtils.e("加载分享数据");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case 2:
                try {

                    Serializable data = intent.getSerializableExtra("data");
                    tuiDetailData = (ShareArticlesRes.DataBean) data;
                    newId = tuiDetailData.getArticle_id();
                    LogUtils.e("加载分享数据");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;

            case 3:
                try {
                    Serializable data = intent.getSerializableExtra("data");
                    favoriteDetailData = (FavotityListGetModle.DataBean) data;

                    newId = favoriteDetailData.getTarget_id();
                    LogUtils.e("加载分享数据");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;

        }

        newsDetails.setWebChromeClient(new WebChromeClient());
        WebSettings settings = newsDetails.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setJavaScriptEnabled(true);//支持javascript
        settings.setUseWideViewPort(true);//适配屏幕
        settings.setLoadWithOverviewMode(true);
        settings.setBuiltInZoomControls(true);//支持放大缩小
        settings.setDisplayZoomControls(false);//隐藏放大缩小的按钮
        settings.setDomStorageEnabled(true);//支持Html5标签
        settings.setJavaScriptCanOpenWindowsAutomatically(true);

        newsDetails.loadUrl(newUrl);
        newsDetails.registerHandler("Appinteractive", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                LogUtils.e("指定Handler接收来自web的数据：" + data);

                try {
                    JSONObject jsonObject = new JSONObject(data);
                    String method = jsonObject.getString("method");
                    if (method != null && method.equals("goto_bbs")) {
                        //:{"category_first_id":0,"category_second_id":0}
                        JSONObject data1 = jsonObject.getJSONObject("data");
                        int category_first_id = data1.getInt("category_first_id");
                        int category_second_id = data1.getInt("category_second_id");
                        Intent intent = new Intent(News_DetailsActivity.this, Plate_DetialActivity.class);
                        intent.putExtra("firstID", category_first_id);
                        intent.putExtra("secondID", category_second_id);
                        startActivity(intent);

                    } else {
                        if (method != null && method.equals("goto_fllow")) {
                            clickToGuanZhu(method);
                            //,"data":{"uid":24727,"follower_state":1}}
                            JSONObject data1 = jsonObject.getJSONObject("data");
                            //       data1.getString("follower_state");
                            String uid = data1.getString("uid");
                            int follower_state = data1.getInt("follower_state");

                            if (uid == null) {

                            } else {
                                if (follower_state == 1) {
                                    addFollowUser(1, uid);
                                } else {
                                    addFollowUser(2, uid);
                                }

                            }

                        }
                    }
                } catch (Exception e) {


                }


                function.onCallBack("指定Handler收到Web发来的数据，回传数据给你");
            }


        });

        addAd.setMyClick(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (memberId == 0) {
                    LogUtils.startToash(News_DetailsActivity.this, AppConstant.PleaseLogin);
                } else {
                    Intent intent = new Intent(News_DetailsActivity.this, News_AddAD_DetailActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("NewsUrl", newUrl);
                    intent.putExtras(bundle);
                    startActivity(intent);
                }

            }
        });

    }


    private void clickToGuanZhu(String json) {

    }

    ProgressDialog progressDialog;

    private void showSelectStyle() {
        String[] items = getResources().getStringArray(R.array.item);
        AlertDialog dialog = new AlertDialog.Builder(News_DetailsActivity.this).setItems(items, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                    case 0://添加广告
                        if (uid != 0) {
                            progressDialog = ProgressDialog.show(News_DetailsActivity.this, "", "植入广告中，请稍后……");
                            progressDialog.setCancelable(true);//设置进度条是否可以按退回键取消
                            progressDialog.setCanceledOnTouchOutside(true);
                         /*   setAddADShare();*/
                            shareDialogUtils.shareAd(progressDialog, uid, newUrl);
                        } else {
                            IntentUtils.openActivity(News_DetailsActivity.this, LoginActivity.class);
                        }
                        break;
                    case 1://直接分享
                        shareDialogUtils.share(newsDetailData);
                        //  setShareDate(shareData);
                        //   ShareDialogUtils.showShareView(News_DetailsActivity.this, imageNewsDetailsShare, sharePopCallBack);
                        break;
                    case 2:
                        dialog.dismiss();
                        break;
                }
            }
        }).create();
        Window window = dialog.getWindow();
        window.setGravity(Gravity.BOTTOM);  //此处可以设置dialog显示的位置
        dialog.show();
    }

    public void setAddADShare() {
        UserServiceImpl.getAdTemp(uid + "", new NetworkSubscriber<GetAdvertByUidRes>() {
            @Override
            public int onSuccess(GetAdvertByUidRes data) {
                super.onSuccess(data);
                LogUtils.e("setaddADShareSuccess");
                if (data != null && data.getCode() == 0) {
                    if ((data.getData().getBottom().size() > 0) || (data.getData().getTop().size() > 0)) {
                        pasterNewsUrl(newUrl);
                    } else {
                        IntentUtils.openActivity(News_DetailsActivity.this, AdEditorActivity.class);
                    }
                } else {
                    ToastUtils.show(News_DetailsActivity.this, data.getMsg());
                    progressDialog.dismiss();

                }
                return 0;
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                ToastUtils.show(News_DetailsActivity.this, "获取广告模板失败");
                progressDialog.dismiss();
            }
        });

    }

    public void pasterNewsUrl(String url) {
        /** 用户粘贴文章文章操作 */
        ArticleServiceImpl.pasterNewsUrl(url, new NetworkSubscriber<CommonRes>() {
            @Override
            public int onSuccess(CommonRes data) {
                super.onSuccess(data);
                LogUtils.e("pasterNewsUrl__onSuccess");

                if (data != null && data.getCode() == 0) {
                    String key = data.getData().toString();
                    shareArticle(key);
                } else {
                    progressDialog.dismiss();

                    ToastUtils.show(News_DetailsActivity.this, data.getMsg());
                }
                return 0;
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                LogUtils.e("pasterNewsUrl__onError");

                progressDialog.dismiss();

                ToastUtils.show(News_DetailsActivity.this, "植入广告失败");

            }
        });
    }

    public void shareArticle(String key) {
        ArticleServiceImpl.shareArticle(uid + "", key, 0, new NetworkSubscriber<ShareArticleRes>() {
            @Override
            public int onSuccess(ShareArticleRes data) {
                super.onSuccess(data);
                if (data != null && data.getCode() == 0) {
                    ShareArticleRes.DataBean shareData = data.getData();
                    articleId = shareData.getArticle_member_id();
                    progressDialog.dismiss();
                    setShareDate(shareData);
                    //   ShareDialogUtils.showShareView(News_DetailsActivity.this, imageNewsDetailsShare, sharePopCallBack);

                } else {
                    progressDialog.dismiss();
                    ToastUtils.show(News_DetailsActivity.this, data.getMsg());
                }
                return 0;
            }
        });
    }

    private Bitmap bitmap;
    ShareDialogUtils.SharePopCallBack sharePopCallBack = new ShareDialogUtils.SharePopCallBack() {
        @Override
        public void Call(AdapterView<?> adapterView, View view, int i, long l) {

            switch (i) {
                case 0:
                    ShareUtils.share(News_DetailsActivity.this, shareInfo);

                    break;
                case 1:
                    ShareUtils.toolShareWechat(News_DetailsActivity.this, shareInfo);

                    break;
                case 2:
                    ShareUtils.shareQQ(shareInfo);

                    break;
                case 3:
                    ShareUtils.shareQZone(shareInfo);

                    break;
                case 4:

                    if (shareInfo.getImgUrl() != null) {
                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                bitmap = Tool.getbitmapFromUrl(shareInfo.getImgUrl());


                                ShareUtils.shareSinaWeibo(News_DetailsActivity.this, shareInfo, bitmap);
                                handler.sendEmptyMessage(0);
                            }
                        }).start();

                    }
                    break;
                case 5:
                    ShareUtils.shareSinaWeiboMessage(shareInfo);

                    break;


            }

        }
    };
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            ShareUtils.shareSinaWeibo(News_DetailsActivity.this, shareInfo, bitmap);

        }
    };

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.detail_Back) {
            finish();
        } else if (view.getId() == R.id.detail_More) {

            if (memberId == 0) {
                LogUtils.startToash(this, AppConstant.PleaseLogin);
            } else {
                showSelectStyle();
            }
        } else if (view.getId() == R.id.image_NewsDetails_Write) {
            if (memberId == 0) {
                LogUtils.startToash(this, AppConstant.PleaseLogin);
            } else {
                clickComment(this, imageNewsDetailsWrite);
            }


        } else if (view.getId() == R.id.image_NewsDetails_Comment) {

            if (memberId == 0) {
                LogUtils.startToash(this, AppConstant.PleaseLogin);
            } else {
                showSelectStyle();
            }

        } else if (view.getId() == R.id.image_NewsDetails_ShouChang) {
            if (memberId == 0) {
                LogUtils.startToash(this, AppConstant.PleaseLogin);
            } else {
                clickShouChang();
            }


        } else if (view.getId() == R.id.image_NewsDetails_Share) {
            if (memberId == 0) {
                LogUtils.startToash(this, AppConstant.PleaseLogin);
            } else {
                showSelectStyle();
            }


        }
    }


    public void clickComment(final Activity mActivity, View view) {

        customPopupForComment = new PopupForComment(mActivity, new PopupForComment.CommentCallBack() {
            @Override
            public void call(String comment) {
                int comentType = 2;
                switch (type) {
                    case 0:
                        comentType = 1;
                    case 1:
                        comentType = 2;
                    case 2:
                        comentType = 2;
                    case 3:
                        comentType = 2;

                }
                sentComment2(comentType, newId, 0, comment);

            }
        });

        customPopupForComment.openKeyboard();
        Tool.setAlpha(mActivity, 0.6f);
        customPopupForComment.showAtLocation(view,
                Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }


    private void clickShouChang() {
        String advert_id = null;
        int style = 0;

        switch (type) {
            case 0:
                /*收藏新闻文章*/
                style = 1;
                advert_id = newsDetailData.getAdvert_id();
                break;
            case 1:
                /*收藏帖子文章*/
                style = 2;
                advert_id = plateDetailData.getPost_id() + "";

                break;
            case 2:
                /*收藏新闻文章*/
                style = 1;
                advert_id = tuiDetailData.getArticle_id() + "";
                break;
        }
        if (advert_id != null && !advert_id.equals("")) {
            if (isShouChang) {
                isShouChang = false;
                addFavority(style, advert_id);
                switch (type) {
                    case 1:
                        plateDetailData.setIs_favorite(0);
                        break;
                }

            } else {
                isShouChang = true;
                DelFavority(style, advert_id);
                switch (type) {
                    case 1:
                        plateDetailData.setIs_favorite(1);
                        break;
                }

            }
        } else {
            LogUtils.startToash(News_DetailsActivity.this, "无法获取该文章标识");
        }


    }

    public void setShareDate(SelectByCategoryIdRes.ValueBean shareData) {

        if (shareData != null) {
            shareInfo = new ShareInfo();
            shareInfo.setUrl(shareData.getShare_url());
            //   shareInfo.setArticleId(Tool.getIntFromString(shareData.getAdvert_id()));


            if (shareData.getImage() != null && shareData.getImage().size() != 0) {
                shareInfo.setImgUrl(shareData.getImage().get(0));
            }


            if (TextUtils.isEmpty(shareData.getDes().trim())) {

                shareInfo.setText(shareData.getTitle());
            } else {

                String des = shareData.getDes();

                shareInfo.setText(des.substring(0, 20));
            }
            shareInfo.setTitle(shareData.getTitle());
        }

    }

    public void setShareDate(ShareArticleRes.DataBean shareData) {

        if (shareData != null) {
            shareInfo = new ShareInfo();
            shareInfo.setUrl(shareData.getShare_url());
            shareInfo.setArticleId(shareData.getArticle_member_id());
            shareInfo.setImgUrl(shareData.getTitle_pic_url());
            if (TextUtils.isEmpty(shareData.getSummary().trim())) {
                shareInfo.setText(shareData.getTitle());
            } else {
                shareInfo.setText(shareData.getSummary());
            }

            shareInfo.setTitle(shareData.getTitle());
        }

    }


    public void addFavority(int style, String newid) {
        if (newid == null || newid.equals("")) {
            LogUtils.startToash(News_DetailsActivity.this, AppConstant.NewsNO);
            return;
        }
        LogUtils.e("添加收藏id" + newid);
        UserServiceImpl.AddFavorites(style, newid, new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody body = response.body();
                if (body == null) {
                    LogUtils.startToash(News_DetailsActivity.this, AppConstant.shouchang_add_error);

                    ResponseBody responseBody = response.errorBody();
                    try {
                        LogUtils.e(responseBody.string());

                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } else {
                    try {
                        LogUtils.e(body.string());
                        ClickUtils.clickShouChang(News_DetailsActivity.this, imageShouChang, true);
                        LogUtils.startToash(News_DetailsActivity.this, AppConstant.shouchang_add_succ);

                        idShouChang = false;
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                LogUtils.e("succ");
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                LogUtils.e("error" + t.getMessage());
                LogUtils.startToash(News_DetailsActivity.this, AppConstant.shouchang_add_error);

            }
        });
    }


    public void DelFavority(int style, String newid) {

        LogUtils.e("删除收藏id" + newid);
        UserServiceImpl.DelFavorites(style, newid, new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody body = response.body();
                if (body == null) {
                    LogUtils.startToash(News_DetailsActivity.this, AppConstant.shouchang_quxiao_error);

                    ResponseBody responseBody = response.errorBody();
                    try {
                        LogUtils.e(responseBody.string());

                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } else {
                    try {
                        LogUtils.e(body.string());
                        ClickUtils.clickShouChang(News_DetailsActivity.this, imageShouChang, false);
                        isShouChang = true;
                        LogUtils.startToash(News_DetailsActivity.this, AppConstant.shouchang_quxiao_succ);
                    } catch (IOException e) {
                        LogUtils.startToash(News_DetailsActivity.this, AppConstant.shouchang_quxiao_error);

                    }
                }
                LogUtils.e("succ");
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                LogUtils.e("error" + t.getMessage());
                LogUtils.startToash(News_DetailsActivity.this, AppConstant.shouchang_quxiao_error);


            }
        });
    }


    public void addFollowUser(final int type, String to_uid) {
        if (memberId == 0) {
            LogUtils.startToash(this, AppConstant.PleaseLogin);
            return;
        }
        int intFromString = Tool.getIntFromString(to_uid);
        if (memberId == intFromString) {
            LogUtils.startToash(this, AppConstant.userself);
            return;
        }
        //type  1 添加关注  2 取消关注
        UserServiceImpl.addFollowerUser(this, type, to_uid, new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                try {
                    ResponseBody body = response.body();
                    if (body != null) {

                        LogUtils.startToash(News_DetailsActivity.this, body.string());
                        newsDetails.loadUrl(newUrl);


                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    LogUtils.startToash(News_DetailsActivity.this, "失败");

                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                if (type == 1) {
                    LogUtils.startToash(News_DetailsActivity.this, AppConstant.guanzhu_add_error);

                } else {
                    LogUtils.startToash(News_DetailsActivity.this, AppConstant.guanzhu_quxiao_error);

                }


            }
        });
    }


    public void sentComment(int comtype, int target_id, int comment_id, String content) {
        LogUtils.e(comtype + " , " + target_id + " , " + comment_id + "  " + content);
        //1新闻 2帖子 3视频
        UserServiceImpl.Comment(2, target_id, comment_id, content, new Subscriber<ResponseBody>() {
            @Override
            public void onCompleted() {
                LogUtils.startToash(News_DetailsActivity.this, "评论取消");
            }

            @Override
            public void onError(Throwable e) {
                LogUtils.startToash(News_DetailsActivity.this, "评论失败");

            }

            @Override
            public void onNext(ResponseBody responseBody) {
                LogUtils.startToash(News_DetailsActivity.this, "评论成功");
            }
        });
    }

    public void sentComment2(int comtype, int target_id, int comment_id, String content) {
        if (target_id == 0) {
            LogUtils.startToash(News_DetailsActivity.this, AppConstant.NewsNO);
            return;
        }
        LogUtils.e(comtype + " , " + target_id + " , " + comment_id + "  " + content);
        //1新闻 2帖子 3视频
        UserServiceImpl.Comment2(2, target_id, comment_id, content, new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                ResponseBody body = response.body();
                if (body == null) {
                    ResponseBody responseBody = response.errorBody();
                    if (responseBody == null) {

                    }
                } else {
                    LogUtils.startToash(News_DetailsActivity.this, "评论成功");

                }
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                LogUtils.startToash(News_DetailsActivity.this, "评论失败");

            }
        });
    }
}
